package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.AlgsNewExperiment;
import com.ruoyi.system.service.IAlgsNewExperimentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 申请新实验Controller
 * 
 * @author ruoyi
 * @date 2023-03-16
 */
@RestController
@RequestMapping("/experiment")
public class AlgsNewExperimentController extends BaseController
{
    @Autowired
    private IAlgsNewExperimentService algsNewExperimentService;

    /**
     * 查询申请新实验列表
     */
//    @RequiresPermissions("experiment:experiment:list")
    @GetMapping("/list")
    public TableDataInfo list(AlgsNewExperiment algsNewExperiment)
    {
        startPage();
        List<AlgsNewExperiment> list = algsNewExperimentService.selectAlgsNewExperimentList(algsNewExperiment);
        return getDataTable(list);
    }

    /**
     * 导出申请新实验列表
     */
//    @RequiresPermissions("experiment:experiment:export")
    @Log(title = "申请新实验", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsNewExperiment algsNewExperiment)
    {
        List<AlgsNewExperiment> list = algsNewExperimentService.selectAlgsNewExperimentList(algsNewExperiment);
        ExcelUtil<AlgsNewExperiment> util = new ExcelUtil<AlgsNewExperiment>(AlgsNewExperiment.class);
        util.exportExcel(response, list, "申请新实验数据");
    }

    /**
     * 获取申请新实验详细信息
     */
//    @RequiresPermissions("experiment:experiment:query")
    @GetMapping(value = "/{newExperimentId}")
    public AjaxResult getInfo(@PathVariable("newExperimentId") Long newExperimentId)
    {
        return success(algsNewExperimentService.selectAlgsNewExperimentByNewExperimentId(newExperimentId));
    }

    /**
     * 新增申请新实验
     */
//    @RequiresPermissions("experiment:experiment:add")
    @Log(title = "申请新实验", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgsNewExperiment algsNewExperiment)
    {
        return toAjax(algsNewExperimentService.insertAlgsNewExperiment(algsNewExperiment));
    }

    /**
     * 修改申请新实验
     */
//    @RequiresPermissions("experiment:experiment:edit")
    @Log(title = "申请新实验", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgsNewExperiment algsNewExperiment)
    {
        return toAjax(algsNewExperimentService.updateAlgsNewExperiment(algsNewExperiment));
    }

    /**
     * 删除申请新实验
     */
//    @RequiresPermissions("experiment:experiment:remove")
    @Log(title = "申请新实验", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newExperimentIds}")
    public AjaxResult remove(@PathVariable Long[] newExperimentIds)
    {
        return toAjax(algsNewExperimentService.deleteAlgsNewExperimentByNewExperimentIds(newExperimentIds));
    }
}
